Create PureBasic structure from any SAP table

Share your advanced PureBasic knowledge/code with the community.
User avatar
Stefan Schnell
User
User
Posts: 85
Joined: Wed May 07, 2003 2:53 pm
Location: Germany - Oberirsen
Contact:

Create PureBasic structure from any SAP table

Post by Stefan Schnell »

Hello community,
here is a small ABAP program to create a PureBasic structure from any SAP table you want.
Cheers
Stefan

Code: Select all

"-Begin-----------------------------------------------------------------
  Report zCreatePureBasStrucFromTable.

    "-Main--------------------------------------------------------------
      Perform CreateStruc Using 'USR01'.

    "-Sub CreateStruc---------------------------------------------------
      Form CreateStruc Using TableName Type String.

        "-Structures----------------------------------------------------
          Types: Begin Of TableStruc,
                   TabName Type DD03L-TABNAME,
                   FieldName Type DD03L-FIELDNAME,
                   Position Type DD03L-POSITION,
                   IntType Type DD03L-INTTYPE,
                   IntLen Type DD03L-INTLEN,
                End Of TableStruc.

        "-Variables-----------------------------------------------------
          Data ResultTable Type Table Of TableStruc.
          Field-Symbols <ResultTable> Type TableStruc.
          Data FieldName Type String.
          Data iIntLen Type Integer.
          Data strIntLen Type String.

        "-Get structure data from DD03L table---------------------------
          Select * From DD03L Into Corresponding Fields Of Table
            ResultTable Where TABNAME = TableName Order By Position.

        "-Write structure data------------------------------------------
          Write: / `  ; Structure from Table ` No-Gap.
          Write: TableName No-Gap.

          Write: / `    Structure str` No-Gap.
          Write: TableName.

          Loop At ResultTable Assigning <ResultTable>.
            Write: / `      ` No-Gap.
            FieldName = <ResultTable>-FieldName.
            Condense FieldName.
            Write: FieldName No-Gap.
            Case <ResultTable>-IntType.
              "-Signed 4-Byte integer-----------------------------------
                When 'I'.
                  Write: `.l`.
              "-Floating point 8-Byte-----------------------------------
                When 'F'.
                  Write: `.d`.
              "-Each other as fixed string------------------------------
                When Others.
                  Write: `.s{` No-Gap.
                  iIntLen = <ResultTable>-IntLen.
                  strIntLen = iIntLen.
                  Condense strIntLen.
                  Write: strIntLen No-Gap.
                  Write: `}`.
            EndCase.
          EndLoop.

        Write: / `    EndStructure`.
        Write: /.

      EndForm.

"-End-------------------------------------------------------------------
Here is the table USR01:

Code: Select all

MANDT	CLNT	3
BNAME	CHAR	12
STCOD	CHAR	20
SPLD	CHAR	4
SPLG	CHAR	1
SPDB	CHAR	1
SPDA	CHAR	1
DATFM	CHAR	1
DCPFM	CHAR	1
HDEST	CHAR	8
HMAND	CLNT	3
HNAME	CHAR	12
MENON	CHAR	1
MENUE	CHAR	20
STRTT	CHAR	20
LANGU	LANG	1
CATTKENNZ	CHAR	1
TIMEFM	CHAR	1
Here is the result from the table USR01:

Code: Select all

; Structure from Table USR01
  Structure strUSR01
    MANDT.s{3}
    BNAME.s{12}
    STCOD.s{20}
    SPLD.s{4}
    SPLG.s{1}
    SPDB.s{1}
    SPDA.s{1}
    DATFM.s{1}
    DCPFM.s{1}
    HDEST.s{8}
    HMAND.s{3}
    HNAME.s{12}
    MENON.s{1}
    MENUE.s{20}
    STRTT.s{20}
    LANGU.s{1}
    CATTKENNZ.s{1}
    TIMEFM.s{1}
  EndStructure
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Create PureBasic structure from any SAP table

Post by doctorized »

Stefan Schnell wrote:here is a small ABAP program
Why should we use ABAP to do the job and not PB?
Captn. Jinguji
User
User
Posts: 94
Joined: Sun Oct 24, 2004 9:25 am

Re: Create PureBasic structure from any SAP table

Post by Captn. Jinguji »

doctorized wrote:
Stefan Schnell wrote:here is a small ABAP program
Why should we use ABAP to do the job and not PB?
Because Stefan GENERATES the PB structure by just supplying the table's name to his program.
ABAP has access to the SAP system's active data dictionary.

Of course, this is only relevant to those of us who need to access SAP from outside.

Thank you, Stefan!
Is this an artifact or should it be disposed of ?
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Create PureBasic structure from any SAP table

Post by doctorized »

Captn. Jinguji wrote:Of course, this is only relevant to those of us who need to access SAP from outside.
You didn't answer my question. Why should we use ABAP to create the PB structure and not PB? If we have the SAP table then it is simple for PB to create the structure.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Create PureBasic structure from any SAP table

Post by Shield »

Because ABAP has direct access to all the tables on the SAP system.
You can request information from any database by using it just like a variable,
so acquiring data is usually much simpler.

(Well, despite the fact ABAP being the absolute worst and most messed up programming language out there, ...).

I doubt you could access tables on an SAP system like regular databases,
so you'd need to use their RFC protocol.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Captn. Jinguji
User
User
Posts: 94
Joined: Sun Oct 24, 2004 9:25 am

Re: Create PureBasic structure from any SAP table

Post by Captn. Jinguji »

doctorized wrote:
Captn. Jinguji wrote:Of course, this is only relevant to those of us who need to access SAP from outside.
You didn't answer my question. Why should we use ABAP to create the PB structure and not PB? If we have the SAP table then it is simple for PB to create the structure.
Ok, show us how you create the structures for table BSEG and table Z9I_STK_IF_NPV.
Is this an artifact or should it be disposed of ?
User avatar
Stefan Schnell
User
User
Posts: 85
Joined: Wed May 07, 2003 2:53 pm
Location: Germany - Oberirsen
Contact:

Re: Create PureBasic structure from any SAP table

Post by Stefan Schnell »

Hello Captn. Jinguji and Shield,
thanks for your explanations.
Cheers
Stefan
Post Reply