ABAP Select data from SAP table PS0586 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 PS0586 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 PS0586. 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 PS0586 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_PS0586 TYPE STANDARD TABLE OF PS0586,
      WA_PS0586 TYPE PS0586,
      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: <PS0586> TYPE PS0586.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PS0586
*  INTO TABLE @DATA(IT_PS05862).
*--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_PS0586 INDEX 1 INTO DATA(WA_PS05862).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PS0586 ASSIGNING <PS0586>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS0586>-WAEHI = 1.
<PS0586>-ACOPC = 1.
<PS0586>-ITC01 = 1.
<PS0586>-PIN01 = 1.
<PS0586>-AIN01 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PS0586-ITC02, sy-vline,
WA_PS0586-PIN02, sy-vline,
WA_PS0586-AIN02, sy-vline,
WA_PS0586-ITC03, sy-vline,
WA_PS0586-PIN03, sy-vline,
WA_PS0586-AIN03, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS0586 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_PS0586 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_PS0586 INTO WA_PS0586. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_PS0586_STR,
WAEHI TYPE STRING,
ACOPC TYPE STRING,
ITC01 TYPE STRING,
PIN01 TYPE STRING,
AIN01 TYPE STRING,
ITC02 TYPE STRING,
PIN02 TYPE STRING,
AIN02 TYPE STRING,
ITC03 TYPE STRING,
PIN03 TYPE STRING,
AIN03 TYPE STRING,
ITC04 TYPE STRING,
PIN04 TYPE STRING,
AIN04 TYPE STRING,
ITC05 TYPE STRING,
PIN05 TYPE STRING,
AIN05 TYPE STRING,
ITC06 TYPE STRING,
PIN06 TYPE STRING,
AIN06 TYPE STRING,
ITC07 TYPE STRING,
PIN07 TYPE STRING,
AIN07 TYPE STRING,
ITC08 TYPE STRING,
PIN08 TYPE STRING,
AIN08 TYPE STRING,
ITC09 TYPE STRING,
PIN09 TYPE STRING,
AIN09 TYPE STRING,
ITC10 TYPE STRING,
PIN10 TYPE STRING,
AIN10 TYPE STRING,
ITC11 TYPE STRING,
PIN11 TYPE STRING,
AIN11 TYPE STRING,
ITC12 TYPE STRING,
PIN12 TYPE STRING,
AIN12 TYPE STRING,
ITC13 TYPE STRING,
PIN13 TYPE STRING,
AIN13 TYPE STRING,
ITC14 TYPE STRING,
PIN14 TYPE STRING,
AIN14 TYPE STRING,
ITC15 TYPE STRING,
PIN15 TYPE STRING,
AIN15 TYPE STRING,
ITC16 TYPE STRING,
PIN16 TYPE STRING,
AIN16 TYPE STRING,
ITC17 TYPE STRING,
PIN17 TYPE STRING,
AIN17 TYPE STRING,
ITC18 TYPE STRING,
PIN18 TYPE STRING,
AIN18 TYPE STRING,
ITC19 TYPE STRING,
PIN19 TYPE STRING,
AIN19 TYPE STRING,
ITC20 TYPE STRING,
PIN20 TYPE STRING,
AIN20 TYPE STRING,
ITC21 TYPE STRING,
PIN21 TYPE STRING,
AIN21 TYPE STRING,
ITC22 TYPE STRING,
PIN22 TYPE STRING,
AIN22 TYPE STRING,
ITC23 TYPE STRING,
PIN23 TYPE STRING,
AIN23 TYPE STRING,
ITC24 TYPE STRING,
PIN24 TYPE STRING,
AIN24 TYPE STRING,
ITC25 TYPE STRING,
PIN25 TYPE STRING,
AIN25 TYPE STRING,
ITC26 TYPE STRING,
PIN26 TYPE STRING,
AIN26 TYPE STRING,
ITC27 TYPE STRING,
PIN27 TYPE STRING,
AIN27 TYPE STRING,
ITC28 TYPE STRING,
PIN28 TYPE STRING,
AIN28 TYPE STRING,
ITC29 TYPE STRING,
PIN29 TYPE STRING,
AIN29 TYPE STRING,
ITC30 TYPE STRING,
PIN30 TYPE STRING,
AIN30 TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS0586_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_PS0586_STR-WAEHI sy-vline
WA_PS0586_STR-ACOPC sy-vline
WA_PS0586_STR-ITC01 sy-vline
WA_PS0586_STR-PIN01 sy-vline
WA_PS0586_STR-AIN01 sy-vline
WA_PS0586_STR-ITC02 sy-vline
WA_PS0586_STR-PIN02 sy-vline
WA_PS0586_STR-AIN02 sy-vline
WA_PS0586_STR-ITC03 sy-vline
WA_PS0586_STR-PIN03 sy-vline
WA_PS0586_STR-AIN03 sy-vline
WA_PS0586_STR-ITC04 sy-vline
WA_PS0586_STR-PIN04 sy-vline
WA_PS0586_STR-AIN04 sy-vline
WA_PS0586_STR-ITC05 sy-vline
WA_PS0586_STR-PIN05 sy-vline
WA_PS0586_STR-AIN05 sy-vline
WA_PS0586_STR-ITC06 sy-vline
WA_PS0586_STR-PIN06 sy-vline
WA_PS0586_STR-AIN06 sy-vline
WA_PS0586_STR-ITC07 sy-vline
WA_PS0586_STR-PIN07 sy-vline
WA_PS0586_STR-AIN07 sy-vline
WA_PS0586_STR-ITC08 sy-vline
WA_PS0586_STR-PIN08 sy-vline
WA_PS0586_STR-AIN08 sy-vline
WA_PS0586_STR-ITC09 sy-vline
WA_PS0586_STR-PIN09 sy-vline
WA_PS0586_STR-AIN09 sy-vline
WA_PS0586_STR-ITC10 sy-vline
WA_PS0586_STR-PIN10 sy-vline
WA_PS0586_STR-AIN10 sy-vline
WA_PS0586_STR-ITC11 sy-vline
WA_PS0586_STR-PIN11 sy-vline
WA_PS0586_STR-AIN11 sy-vline
WA_PS0586_STR-ITC12 sy-vline
WA_PS0586_STR-PIN12 sy-vline
WA_PS0586_STR-AIN12 sy-vline
WA_PS0586_STR-ITC13 sy-vline
WA_PS0586_STR-PIN13 sy-vline
WA_PS0586_STR-AIN13 sy-vline
WA_PS0586_STR-ITC14 sy-vline
WA_PS0586_STR-PIN14 sy-vline
WA_PS0586_STR-AIN14 sy-vline
WA_PS0586_STR-ITC15 sy-vline
WA_PS0586_STR-PIN15 sy-vline
WA_PS0586_STR-AIN15 sy-vline
WA_PS0586_STR-ITC16 sy-vline
WA_PS0586_STR-PIN16 sy-vline
WA_PS0586_STR-AIN16 sy-vline
WA_PS0586_STR-ITC17 sy-vline
WA_PS0586_STR-PIN17 sy-vline
WA_PS0586_STR-AIN17 sy-vline
WA_PS0586_STR-ITC18 sy-vline
WA_PS0586_STR-PIN18 sy-vline
WA_PS0586_STR-AIN18 sy-vline
WA_PS0586_STR-ITC19 sy-vline
WA_PS0586_STR-PIN19 sy-vline
WA_PS0586_STR-AIN19 sy-vline
WA_PS0586_STR-ITC20 sy-vline
WA_PS0586_STR-PIN20 sy-vline
WA_PS0586_STR-AIN20 sy-vline
WA_PS0586_STR-ITC21 sy-vline
WA_PS0586_STR-PIN21 sy-vline
WA_PS0586_STR-AIN21 sy-vline
WA_PS0586_STR-ITC22 sy-vline
WA_PS0586_STR-PIN22 sy-vline
WA_PS0586_STR-AIN22 sy-vline
WA_PS0586_STR-ITC23 sy-vline
WA_PS0586_STR-PIN23 sy-vline
WA_PS0586_STR-AIN23 sy-vline
WA_PS0586_STR-ITC24 sy-vline
WA_PS0586_STR-PIN24 sy-vline
WA_PS0586_STR-AIN24 sy-vline
WA_PS0586_STR-ITC25 sy-vline
WA_PS0586_STR-PIN25 sy-vline
WA_PS0586_STR-AIN25 sy-vline
WA_PS0586_STR-ITC26 sy-vline
WA_PS0586_STR-PIN26 sy-vline
WA_PS0586_STR-AIN26 sy-vline
WA_PS0586_STR-ITC27 sy-vline
WA_PS0586_STR-PIN27 sy-vline
WA_PS0586_STR-AIN27 sy-vline
WA_PS0586_STR-ITC28 sy-vline
WA_PS0586_STR-PIN28 sy-vline
WA_PS0586_STR-AIN28 sy-vline
WA_PS0586_STR-ITC29 sy-vline
WA_PS0586_STR-PIN29 sy-vline
WA_PS0586_STR-AIN29 sy-vline
WA_PS0586_STR-ITC30 sy-vline
WA_PS0586_STR-PIN30 sy-vline
WA_PS0586_STR-AIN30 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.