ABAP Select data from SAP table PSEISACC2 into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP PSEISACC2 table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to PSEISACC2. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the PSEISACC2 table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_PSEISACC2 TYPE STANDARD TABLE OF PSEISACC2,
      WA_PSEISACC2 TYPE PSEISACC2,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: <PSEISACC2> TYPE PSEISACC2.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_PSEISACC2.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM PSEISACC2
  INTO TABLE IT_PSEISACC2.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PSEISACC2
*  INTO TABLE @DATA(IT_PSEISACC22).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_PSEISACC2 INDEX 1 INTO DATA(WA_PSEISACC22).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PSEISACC2 ASSIGNING <PSEISACC2>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PSEISACC2>-CONARE = 1.
<PSEISACC2>-OWAERS = 1.
<PSEISACC2>-MEINH = 1.
<PSEISACC2>-VERSN = 1.
<PSEISACC2>-VERSA = 1.
ENDLOOP.

LOOP AT IT_PSEISACC2 INTO WA_PSEISACC2.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PSEISACC2-APPL, sy-vline,
WA_PSEISACC2-ACPOS, sy-vline,
WA_PSEISACC2-ACTCOSTS, sy-vline,
WA_PSEISACC2-PLNCOSTS, sy-vline,
WA_PSEISACC2-COMMITMT, sy-vline,
WA_PSEISACC2-PREQCOM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PSEISACC2 you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_PSEISACC2 TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_PSEISACC2 INTO WA_PSEISACC2. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.

*Conversion exit CUNIT, internal->external for field MEINH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PSEISACC2-MEINH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PSEISACC2-MEINH.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field VERSN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PSEISACC2-VERSN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PSEISACC2-VERSN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field VERSA CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PSEISACC2-VERSA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PSEISACC2-VERSA.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_PSEISACC2_STR,
CONARE TYPE STRING,
OWAERS TYPE STRING,
MEINH TYPE STRING,
VERSN TYPE STRING,
VERSA TYPE STRING,
APPL TYPE STRING,
ACPOS TYPE STRING,
ACTCOSTS TYPE STRING,
PLNCOSTS TYPE STRING,
COMMITMT TYPE STRING,
PREQCOM TYPE STRING,
PORDCOM TYPE STRING,
DPMTEXPD TYPE STRING,
ACTLREVS TYPE STRING,
PLANREVS TYPE STRING,
ACTCSTSTSD TYPE STRING,
PLNCSTSTSD TYPE STRING,
ACTREVSTSD TYPE STRING,
PLNREVSTSD TYPE STRING,
ACTCSTSTRS TYPE STRING,
PLNCSTSTRS TYPE STRING,
ACTREVSTRS TYPE STRING,
PLNREVSTRS TYPE STRING,
CSTORDREC TYPE STRING,
CSTORDBAK TYPE STRING,
REVORDREC TYPE STRING,
REVORDBAK TYPE STRING,
ACREVRES TYPE STRING,
ACREVBIL TYPE STRING,
ACREVSUR TYPE STRING,
ACCSTSLS TYPE STRING,
ACWKIP TYPE STRING,
ACSURC TYPE STRING,
ACRESLOS TYPE STRING,
PLREVRES TYPE STRING,
PLREVBIL TYPE STRING,
PLREVSUR TYPE STRING,
PLCSTSLS TYPE STRING,
PLWKIP TYPE STRING,
PLSURC TYPE STRING,
PLRESLOS TYPE STRING,
ORIGBDGT TYPE STRING,
BDGTSUPP TYPE STRING,
BDGTRETN TYPE STRING,
BDGTTRFR TYPE STRING,
CURRBDGT TYPE STRING,
RELDBUDGT TYPE STRING,
CRPAYMPL TYPE STRING,
CRPAYMOB TYPE STRING,
CRDNPYRQ TYPE STRING,
CRDWNPMT TYPE STRING,
CROPNINV TYPE STRING,
CRACTPMT TYPE STRING,
DRPAYMPL TYPE STRING,
DRDNPYRQ TYPE STRING,
DRDWNPMT TYPE STRING,
DROPNINV TYPE STRING,
DRACTPMT TYPE STRING,
OACTCOSTS TYPE STRING,
OPLNCOSTS TYPE STRING,
OCOMMITMT TYPE STRING,
OPREQCOM TYPE STRING,
OPORDCOM TYPE STRING,
ODPMTEXPD TYPE STRING,
OACTLREVS TYPE STRING,
OPLANREVS TYPE STRING,
OACTCSTSTSD TYPE STRING,
OPLNCSTSTSD TYPE STRING,
OACTREVSTSD TYPE STRING,
OPLNREVSTSD TYPE STRING,
OACTCSTSTRS TYPE STRING,
OPLNCSTSTRS TYPE STRING,
OACTREVSTRS TYPE STRING,
OPLNREVSTRS TYPE STRING,
OCSTORDREC TYPE STRING,
OCSTORDBAK TYPE STRING,
OREVORDREC TYPE STRING,
OREVORDBAK TYPE STRING,
OACREVRES TYPE STRING,
OACREVBIL TYPE STRING,
OACREVSUR TYPE STRING,
OACCSTSLS TYPE STRING,
OACWKIP TYPE STRING,
OACSURC TYPE STRING,
OACRESLOS TYPE STRING,
OPLREVRES TYPE STRING,
OPLREVBIL TYPE STRING,
OPLREVSUR TYPE STRING,
OPLCSTSLS TYPE STRING,
OPLWKIP TYPE STRING,
OPLSURC TYPE STRING,
OPLRESLOS TYPE STRING,
OORIGBDGT TYPE STRING,
OBDGTSUPP TYPE STRING,
OBDGTRETN TYPE STRING,
OBDGTTRFR TYPE STRING,
OCURRBDGT TYPE STRING,
ORELDBUDGT TYPE STRING,
OCRPAYMPL TYPE STRING,
OCRPAYMOB TYPE STRING,
OCRDNPYRQ TYPE STRING,
OCRDWNPMT TYPE STRING,
OCROPNINV TYPE STRING,
OCRACTPMT TYPE STRING,
ODRPAYMPL TYPE STRING,
ODRDNPYRQ TYPE STRING,
ODRDWNPMT TYPE STRING,
ODROPNINV TYPE STRING,
ODRACTPMT TYPE STRING,
QTACTREV TYPE STRING,
QTACTKST TYPE STRING,
QTPLNREV TYPE STRING,
QTPLNKST TYPE STRING,
QTCOMMIT TYPE STRING,
QTASTKYA TYPE STRING,
QTASTKYN TYPE STRING,
QTPSTKYA TYPE STRING,
QTPSTKYN TYPE STRING,END OF T_EKKO_STR. DATA: WA_PSEISACC2_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_PSEISACC2_STR-CONARE sy-vline
WA_PSEISACC2_STR-OWAERS sy-vline
WA_PSEISACC2_STR-MEINH sy-vline
WA_PSEISACC2_STR-VERSN sy-vline
WA_PSEISACC2_STR-VERSA sy-vline
WA_PSEISACC2_STR-APPL sy-vline
WA_PSEISACC2_STR-ACPOS sy-vline
WA_PSEISACC2_STR-ACTCOSTS sy-vline
WA_PSEISACC2_STR-PLNCOSTS sy-vline
WA_PSEISACC2_STR-COMMITMT sy-vline
WA_PSEISACC2_STR-PREQCOM sy-vline
WA_PSEISACC2_STR-PORDCOM sy-vline
WA_PSEISACC2_STR-DPMTEXPD sy-vline
WA_PSEISACC2_STR-ACTLREVS sy-vline
WA_PSEISACC2_STR-PLANREVS sy-vline
WA_PSEISACC2_STR-ACTCSTSTSD sy-vline
WA_PSEISACC2_STR-PLNCSTSTSD sy-vline
WA_PSEISACC2_STR-ACTREVSTSD sy-vline
WA_PSEISACC2_STR-PLNREVSTSD sy-vline
WA_PSEISACC2_STR-ACTCSTSTRS sy-vline
WA_PSEISACC2_STR-PLNCSTSTRS sy-vline
WA_PSEISACC2_STR-ACTREVSTRS sy-vline
WA_PSEISACC2_STR-PLNREVSTRS sy-vline
WA_PSEISACC2_STR-CSTORDREC sy-vline
WA_PSEISACC2_STR-CSTORDBAK sy-vline
WA_PSEISACC2_STR-REVORDREC sy-vline
WA_PSEISACC2_STR-REVORDBAK sy-vline
WA_PSEISACC2_STR-ACREVRES sy-vline
WA_PSEISACC2_STR-ACREVBIL sy-vline
WA_PSEISACC2_STR-ACREVSUR sy-vline
WA_PSEISACC2_STR-ACCSTSLS sy-vline
WA_PSEISACC2_STR-ACWKIP sy-vline
WA_PSEISACC2_STR-ACSURC sy-vline
WA_PSEISACC2_STR-ACRESLOS sy-vline
WA_PSEISACC2_STR-PLREVRES sy-vline
WA_PSEISACC2_STR-PLREVBIL sy-vline
WA_PSEISACC2_STR-PLREVSUR sy-vline
WA_PSEISACC2_STR-PLCSTSLS sy-vline
WA_PSEISACC2_STR-PLWKIP sy-vline
WA_PSEISACC2_STR-PLSURC sy-vline
WA_PSEISACC2_STR-PLRESLOS sy-vline
WA_PSEISACC2_STR-ORIGBDGT sy-vline
WA_PSEISACC2_STR-BDGTSUPP sy-vline
WA_PSEISACC2_STR-BDGTRETN sy-vline
WA_PSEISACC2_STR-BDGTTRFR sy-vline
WA_PSEISACC2_STR-CURRBDGT sy-vline
WA_PSEISACC2_STR-RELDBUDGT sy-vline
WA_PSEISACC2_STR-CRPAYMPL sy-vline
WA_PSEISACC2_STR-CRPAYMOB sy-vline
WA_PSEISACC2_STR-CRDNPYRQ sy-vline
WA_PSEISACC2_STR-CRDWNPMT sy-vline
WA_PSEISACC2_STR-CROPNINV sy-vline
WA_PSEISACC2_STR-CRACTPMT sy-vline
WA_PSEISACC2_STR-DRPAYMPL sy-vline
WA_PSEISACC2_STR-DRDNPYRQ sy-vline
WA_PSEISACC2_STR-DRDWNPMT sy-vline
WA_PSEISACC2_STR-DROPNINV sy-vline
WA_PSEISACC2_STR-DRACTPMT sy-vline
WA_PSEISACC2_STR-OACTCOSTS sy-vline
WA_PSEISACC2_STR-OPLNCOSTS sy-vline
WA_PSEISACC2_STR-OCOMMITMT sy-vline
WA_PSEISACC2_STR-OPREQCOM sy-vline
WA_PSEISACC2_STR-OPORDCOM sy-vline
WA_PSEISACC2_STR-ODPMTEXPD sy-vline
WA_PSEISACC2_STR-OACTLREVS sy-vline
WA_PSEISACC2_STR-OPLANREVS sy-vline
WA_PSEISACC2_STR-OACTCSTSTSD sy-vline
WA_PSEISACC2_STR-OPLNCSTSTSD sy-vline
WA_PSEISACC2_STR-OACTREVSTSD sy-vline
WA_PSEISACC2_STR-OPLNREVSTSD sy-vline
WA_PSEISACC2_STR-OACTCSTSTRS sy-vline
WA_PSEISACC2_STR-OPLNCSTSTRS sy-vline
WA_PSEISACC2_STR-OACTREVSTRS sy-vline
WA_PSEISACC2_STR-OPLNREVSTRS sy-vline
WA_PSEISACC2_STR-OCSTORDREC sy-vline
WA_PSEISACC2_STR-OCSTORDBAK sy-vline
WA_PSEISACC2_STR-OREVORDREC sy-vline
WA_PSEISACC2_STR-OREVORDBAK sy-vline
WA_PSEISACC2_STR-OACREVRES sy-vline
WA_PSEISACC2_STR-OACREVBIL sy-vline
WA_PSEISACC2_STR-OACREVSUR sy-vline
WA_PSEISACC2_STR-OACCSTSLS sy-vline
WA_PSEISACC2_STR-OACWKIP sy-vline
WA_PSEISACC2_STR-OACSURC sy-vline
WA_PSEISACC2_STR-OACRESLOS sy-vline
WA_PSEISACC2_STR-OPLREVRES sy-vline
WA_PSEISACC2_STR-OPLREVBIL sy-vline
WA_PSEISACC2_STR-OPLREVSUR sy-vline
WA_PSEISACC2_STR-OPLCSTSLS sy-vline
WA_PSEISACC2_STR-OPLWKIP sy-vline
WA_PSEISACC2_STR-OPLSURC sy-vline
WA_PSEISACC2_STR-OPLRESLOS sy-vline
WA_PSEISACC2_STR-OORIGBDGT sy-vline
WA_PSEISACC2_STR-OBDGTSUPP sy-vline
WA_PSEISACC2_STR-OBDGTRETN sy-vline
WA_PSEISACC2_STR-OBDGTTRFR sy-vline
WA_PSEISACC2_STR-OCURRBDGT sy-vline
WA_PSEISACC2_STR-ORELDBUDGT sy-vline
WA_PSEISACC2_STR-OCRPAYMPL sy-vline
WA_PSEISACC2_STR-OCRPAYMOB sy-vline
WA_PSEISACC2_STR-OCRDNPYRQ sy-vline
WA_PSEISACC2_STR-OCRDWNPMT sy-vline
WA_PSEISACC2_STR-OCROPNINV sy-vline
WA_PSEISACC2_STR-OCRACTPMT sy-vline
WA_PSEISACC2_STR-ODRPAYMPL sy-vline
WA_PSEISACC2_STR-ODRDNPYRQ sy-vline
WA_PSEISACC2_STR-ODRDWNPMT sy-vline
WA_PSEISACC2_STR-ODROPNINV sy-vline
WA_PSEISACC2_STR-ODRACTPMT sy-vline
WA_PSEISACC2_STR-QTACTREV sy-vline
WA_PSEISACC2_STR-QTACTKST sy-vline
WA_PSEISACC2_STR-QTPLNREV sy-vline
WA_PSEISACC2_STR-QTPLNKST sy-vline
WA_PSEISACC2_STR-QTCOMMIT sy-vline
WA_PSEISACC2_STR-QTASTKYA sy-vline
WA_PSEISACC2_STR-QTASTKYN sy-vline
WA_PSEISACC2_STR-QTPSTKYA sy-vline
WA_PSEISACC2_STR-QTPSTKYN sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.