ABAP Select data from SAP table PIQCORR_STRU_CMS0_ACWORK 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 PIQCORR_STRU_CMS0_ACWORK 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 PIQCORR_STRU_CMS0_ACWORK. 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 PIQCORR_STRU_CMS0_ACWORK 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_PIQCORR_STRU_CMS0_ACWORK TYPE STANDARD TABLE OF PIQCORR_STRU_CMS0_ACWORK, WA_PIQCORR_STRU_CMS0_ACWORK TYPE PIQCORR_STRU_CMS0_ACWORK, 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: <PIQCORR_STRU_CMS0_ACWORK> TYPE PIQCORR_STRU_CMS0_ACWORK. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PIQCORR_STRU_CMS0_ACWORK. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PIQCORR_STRU_CMS0_ACWORK INTO TABLE IT_PIQCORR_STRU_CMS0_ACWORK. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PIQCORR_STRU_CMS0_ACWORK * INTO TABLE @DATA(IT_PIQCORR_STRU_CMS0_ACWORK2). *--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_PIQCORR_STRU_CMS0_ACWORK INDEX 1 INTO DATA(WA_PIQCORR_STRU_CMS0_ACWORK2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PIQCORR_STRU_CMS0_ACWORK ASSIGNING <PIQCORR_STRU_CMS0_ACWORK>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PIQCORR_STRU_CMS0_ACWORK>-WA_ACWORK = 1.
<PIQCORR_STRU_CMS0_ACWORK>-ACADEMICWORKID = 1.
<PIQCORR_STRU_CMS0_ACWORK>-AGRID = 1.
<PIQCORR_STRU_CMS0_ACWORK>-AWOTYPE = 1.
<PIQCORR_STRU_CMS0_ACWORK>-AWOBJID = 1.
ENDLOOP. LOOP AT IT_PIQCORR_STRU_CMS0_ACWORK INTO WA_PIQCORR_STRU_CMS0_ACWORK. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PIQCORR_STRU_CMS0_ACWORK-AWBEGDATE, sy-vline,
WA_PIQCORR_STRU_CMS0_ACWORK-AWENDDATE, sy-vline,
WA_PIQCORR_STRU_CMS0_ACWORK-AWLOCKFLAG, sy-vline,
WA_PIQCORR_STRU_CMS0_ACWORK-AWSTATUS, sy-vline,
WA_PIQCORR_STRU_CMS0_ACWORK-CANCELREASON, sy-vline,
WA_PIQCORR_STRU_CMS0_ACWORK-CANCELDATE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PIQCORR_STRU_CMS0_ACWORK 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_PIQCORR_STRU_CMS0_ACWORK 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_PIQCORR_STRU_CMS0_ACWORK INTO WA_PIQCORR_STRU_CMS0_ACWORK. *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 CPUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PIQCORR_STRU_CMS0_ACWORK-CPUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PIQCORR_STRU_CMS0_ACWORK-CPUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field CPUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PIQCORR_STRU_CMS0_ACWORK-CPUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PIQCORR_STRU_CMS0_ACWORK-CPUNIT.
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_PIQCORR_STRU_CMS0_ACWORK_STR,
WA_ACWORK TYPE STRING,
ACADEMICWORKID TYPE STRING,
AGRID TYPE STRING,
AWOTYPE TYPE STRING,
AWOBJID TYPE STRING,
AWBEGDATE TYPE STRING,
AWENDDATE TYPE STRING,
AWLOCKFLAG TYPE STRING,
AWSTATUS TYPE STRING,
CANCELREASON TYPE STRING,
CANCELDATE TYPE STRING,
BOOKDATE TYPE STRING,
AWRATING TYPE STRING,
CHARGEFREE TYPE STRING,
TRANSFERFLAG TYPE STRING,
EVENTPACKAGE TYPE STRING,
ACAD_SESSION TYPE STRING,
ACAD_YEAR TYPE STRING,
BOOKREASON TYPE STRING,
ANNULMENT TYPE STRING,
COBOK TYPE STRING,
PRIOX TYPE STRING,
ALT_SCALEID TYPE STRING,
AGRTYPE TYPE STRING,
AGRSTAT TYPE STRING,
GRADESYMBOL TYPE STRING,
GRADE TYPE STRING,
GRADESCALE TYPE STRING,
AGRNOTRATED TYPE STRING,
AGRDATE TYPE STRING,
AGRCOMPLETED TYPE STRING,
CPATTEMP TYPE STRING,
CPEARNED TYPE STRING,
CPGRADED TYPE STRING,
CPUNIT TYPE STRING,
AGRREMARK TYPE STRING,
AGRBEGDA TYPE STRING,
AGRENDDA TYPE STRING,
ARCH_STATUS TYPE STRING,
NOTEID TYPE STRING,
GRADECHANGED TYPE STRING,
PUBLICATIONDATE TYPE STRING,
AWTEXT TYPE STRING,
ATTNO_TW TYPE STRING,
WA_ACWORKT TYPE STRING,
ACADEMICWORKID TYPE STRING,
AGRID TYPE STRING,
AWOTYPE TYPE STRING,
AWOBJID TYPE STRING,
AWBEGDATE TYPE STRING,
AWENDDATE TYPE STRING,
AWLOCKFLAG TYPE STRING,
AWSTATUS TYPE STRING,
CANCELREASON TYPE STRING,
CANCELDATE TYPE STRING,
BOOKDATE TYPE STRING,
AWRATING TYPE STRING,
CHARGEFREE TYPE STRING,
TRANSFERFLAG TYPE STRING,
EVENTPACKAGE TYPE STRING,
ACAD_SESSION TYPE STRING,
ACAD_YEAR TYPE STRING,
BOOKREASON TYPE STRING,
ANNULMENT TYPE STRING,
COBOK TYPE STRING,
PRIOX TYPE STRING,
ALT_SCALEID TYPE STRING,
AGRTYPE TYPE STRING,
AGRSTAT TYPE STRING,
GRADESYMBOL TYPE STRING,
GRADE TYPE STRING,
GRADESCALE TYPE STRING,
AGRNOTRATED TYPE STRING,
AGRDATE TYPE STRING,
AGRCOMPLETED TYPE STRING,
CPATTEMP TYPE STRING,
CPEARNED TYPE STRING,
CPGRADED TYPE STRING,
CPUNIT TYPE STRING,
AGRREMARK TYPE STRING,
AGRBEGDA TYPE STRING,
AGRENDDA TYPE STRING,
ARCH_STATUS TYPE STRING,
NOTEID TYPE STRING,
GRADECHANGED TYPE STRING,
PUBLICATIONDATE TYPE STRING,
AWTEXT TYPE STRING,
ATTNO_TW TYPE STRING,
AWOTYPE_TXT TYPE STRING,
AWOBJECT_SHT TYPE STRING,
AWOBJECT_TXT TYPE STRING,
AWSTATUS_TXT TYPE STRING,
CANCELREASON_TXT TYPE STRING,
AWRATING_TXT TYPE STRING,
EVENTPACKAGE_SHT TYPE STRING,
EVENTPACKAGE_TXT TYPE STRING,
ACAD_SESSION_TXT TYPE STRING,
ACAD_YEAR_TXT TYPE STRING,
BOOKREASON_TXT TYPE STRING,
ANNULMENT_TXT TYPE STRING,
AGRTYPE_TXT TYPE STRING,
AGRSTAT_TXT TYPE STRING,
GRADESYMBOL_TXT TYPE STRING,
GRADESCALE_TXT TYPE STRING,
CPUNIT_TXT TYPE STRING,
AGRREMARK_TXT TYPE STRING,
COBOK_TXT TYPE STRING,
T_SMUSAGE TYPE STRING,END OF T_EKKO_STR. DATA: WA_PIQCORR_STRU_CMS0_ACWORK_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_PIQCORR_STRU_CMS0_ACWORK_STR-WA_ACWORK sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ACADEMICWORKID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWOTYPE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWOBJID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWBEGDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWENDDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWLOCKFLAG sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWSTATUS sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CANCELREASON sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CANCELDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-BOOKDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWRATING sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CHARGEFREE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-TRANSFERFLAG sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-EVENTPACKAGE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ACAD_SESSION sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ACAD_YEAR sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-BOOKREASON sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ANNULMENT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-COBOK sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-PRIOX sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ALT_SCALEID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRTYPE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRSTAT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADESYMBOL sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADESCALE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRNOTRATED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRCOMPLETED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CPATTEMP sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CPEARNED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CPGRADED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CPUNIT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRREMARK sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRBEGDA sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRENDDA sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ARCH_STATUS sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-NOTEID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADECHANGED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-PUBLICATIONDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWTEXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ATTNO_TW sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-WA_ACWORKT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ACADEMICWORKID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWOTYPE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWOBJID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWBEGDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWENDDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWLOCKFLAG sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWSTATUS sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CANCELREASON sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CANCELDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-BOOKDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWRATING sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CHARGEFREE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-TRANSFERFLAG sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-EVENTPACKAGE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ACAD_SESSION sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ACAD_YEAR sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-BOOKREASON sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ANNULMENT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-COBOK sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-PRIOX sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ALT_SCALEID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRTYPE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRSTAT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADESYMBOL sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADESCALE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRNOTRATED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRCOMPLETED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CPATTEMP sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CPEARNED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CPGRADED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CPUNIT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRREMARK sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRBEGDA sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRENDDA sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ARCH_STATUS sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-NOTEID sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADECHANGED sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-PUBLICATIONDATE sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWTEXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ATTNO_TW sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWOTYPE_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWOBJECT_SHT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWOBJECT_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWSTATUS_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CANCELREASON_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AWRATING_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-EVENTPACKAGE_SHT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-EVENTPACKAGE_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ACAD_SESSION_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ACAD_YEAR_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-BOOKREASON_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-ANNULMENT_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRTYPE_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRSTAT_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADESYMBOL_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-GRADESCALE_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-CPUNIT_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-AGRREMARK_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-COBOK_TXT sy-vline
WA_PIQCORR_STRU_CMS0_ACWORK_STR-T_SMUSAGE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.