Page 1 of 1

Create PureBasic structure from any SAP table

Posted: Fri Jun 03, 2011 11:29 am
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

Re: Create PureBasic structure from any SAP table

Posted: Mon Jun 06, 2011 2:26 pm
by doctorized
Stefan Schnell wrote:here is a small ABAP program
Why should we use ABAP to do the job and not PB?

Re: Create PureBasic structure from any SAP table

Posted: Tue Jun 07, 2011 6:29 pm
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!

Re: Create PureBasic structure from any SAP table

Posted: Wed Jun 08, 2011 5:59 pm
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.

Re: Create PureBasic structure from any SAP table

Posted: Thu Jun 09, 2011 7:58 am
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.

Re: Create PureBasic structure from any SAP table

Posted: Thu Jun 09, 2011 9:09 am
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.

Re: Create PureBasic structure from any SAP table

Posted: Sun Jun 12, 2011 9:21 pm
by Stefan Schnell
Hello Captn. Jinguji and Shield,
thanks for your explanations.
Cheers
Stefan