Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Howtoaddarecordinadatabasetablefroma...|SCN
GettingStarted Newsletters
Hi,Guest
LogOn
JoinUs
Store
SearchtheCommunity
Products
Services&Support
AboutSCN
Downloads
Industries
Training&Education
Partnership
DeveloperCenter
Activity
LinesofBusiness
UniversityAlliances
Events&Webinars
Innovation
Browse
Communications
Actions
THISDISCUSSIONISLOCKED
81Replies Latestreply:Jan21,20141:35PMbynabheetmadan
Share
Tweet
ManishMalakar
Oct25,20136:34PM
Howtoaddarecordinadatabasetablefroma
tableinmodulepool
ThisquestionisAssumedAnswered.
Helloall,
Ihavecreatedacustomztableinse11with4fields.Nowthese4fieldshave
records.ThenIcreatedatablecontrolusingthese4fieldsinamodulepool.My
requirementistodisplaytherecordsofthefieldsaspertheselectoptions.However,
thereisalsosupposedtobea'SAVE'buttonwhichallowstheusertosaveanew
recordinthetablecontrolwhichshouldalsogetaddedinthedatabasetable(thez
table)thatIcreatedinse11.NowIhaveusedtheMODIFYstatementlikethis:
MODIFYZEMP1FROMTABLEIT_ZEMP1.
However,thenewrecordisnotgettingupdatedinthedatabasetableZEMP1.
DoIhavetousetheMODIFYstatementwiththeworkarea,oristhereanyother
way?Pleasehelp.
HelpfulAnswersbyRamesh.,VladimirErakovic
5826Views
AverageUserRating
(2ratings)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hi,
MODIFYshouldwork,perhapsaCOMMITWORKafterwards.
Martin
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
http://scn.sap.com/thread/3444512
1/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
IdidtryMODIFYwithCOMMITWORK,butitsisntworking.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hi,
AreyousureyourinternaltablehasthedatabeforetheMODIFY?
CouldyoupostascreenshotofitscontentsinDEBUGjustbeforetheMODIFYinstruction?
Martin
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiManish,
Canyoucheckbelowcode.
*YEMP_TEMP1=ismyDDICtable
*IT_APPEND=>ismyinternaltable(oftablecontrol)bothDDICandyourinternaltableshould
*becompatiblethenonlyyoucanuploadtherecord
*itmeansyourtablecontrolmustbefieldmustsamestructureofyourDDICtableelseyou
willget
*belowerror(Attachedscreenshot)
modifyYEMP_TEMP1fromtableit_append.
IFsysubrc=0.
commitwork.
message'Recordupdatedsucessfully'type'S'.
else.
rollbackwork.
ENDIF.
Regards,
Akshath
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiAkshath,
Iusedyourapproach,butthenewrecordisstillnotgettinginsertedinmydatabasetable.
internaltableandworkareaarebothcompatiblewiththedatabasetablefields.
My
Like(0)
http://scn.sap.com/thread/3444512
2/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
MiguelAlvear Oct25,20138:10PM (inresponsetoManishMalakar)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hi.
useupdateorinsert,asyousaidthatanewrecordwillbeadded,soyouneedtoinsertitonthetable,
notmodify.GetmoreinformationpressingF1overtheINSERTstatement.
example:
TABLEzfss2_oa_sap.
DATA:wa_zfss2_oa_sapLIKEzfss2_oa_sap,
INSERTzfss2_oa_sapFROMwa_zfss2_oa_sap.
Regards
Miguel
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiMiguel,IdidtryINSERT,butit'sthrowingadump
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
iamcreatingatableformanualentryinmodulepoolbutproblemiswheneveruserenter
materialnothedescriptionshouldautomaticallycomesinotherfieldandatlastthedatashould
saveinthetableiwillattachyouthescreenshotplsguideme.whenuserpressenterthefield
entrydisappears.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HIAmol,
InPAI.UseChain...EndchainorField<Field>forvalidation.
PAI.
FieldMATNR
Module<Get_Material>.
Module<Get_material>.
Readdatafrom<Table>andpassitintointernaltablewhichyouhaveusedfortable
control.
endmodule.
inPBO.
http://scn.sap.com/thread/3444512
3/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Looptheinternaltableandpasstotablecontrol.
endloop.
Trythis...
Letmeknowyouneedmoreinput.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
NODEARitsnotworking.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Yourrequirementis:
1.Selectmaterialandpressenter>restofthefieldshouldautomaticallypopulate
right.
2.OnceyousaveitshouldsameinDB(Ztables)
Amicorrect?
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HEWILLENTERTHEMATERIALNOANDTHEDESCRIPTIONWILLCOME
AUTOMATICALLYANDRESTOFTHEFIELDHEWILLFILLITBYMANUALLY
LIKEQUANTITYANDBASEUNIT
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodule
pool
http://scn.sap.com/thread/3444512
4/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
PROCESSBEFOREOUTPUT.
*&SPWIZARD:PBOFLOWLOGICFORTABLECONTROL'TCL1'
MODULETCL1_CHANGE_TC_ATTR.
*&SPWIZARD:MODULETCL1_CHANGE_COL_ATTR.
LOOPATIT_MARA
INTOWA_MARA
WITHCONTROLTCL1
CURSORTCL1CURRENT_LINE.
MODULETCL1_GET_LINES.
*&SPWIZARD:MODULETCL1_CHANGE_FIELD_ATTR
ENDLOOP.
MODULESTATUS_0100.
*
PROCESSAFTERINPUT.
*&SPWIZARD:PAIFLOWLOGICFORTABLECONTROL'TCL1'
LOOPATIT_MARA.
CHAIN.
FIELDWA_MARAMATNR.
moduleget_mat.
FIELDWA_MARAMAKTX.
FIELDWA_MARAMTART.
FIELDWA_MARAMBRSH.
FIELDWA_MARAMATKL.
FIELDWA_MARAMEINS.
endchain.
FIELDWA_MARASEL
MODULETCL1_MARKONREQUEST.
ENDLOOP.
MODULETCL1_USER_COMMAND.
*&SPWIZARD:MODULETCL1_CHANGE_TC_ATTR.
*&SPWIZARD:MODULETCL1_CHANGE_COL_ATTR.
MODULEUSER_COMMAND_0100.
CALLFUNCTION'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input=wa_maramatnr
IMPORTING
OUTPUT=wa_maramatnr
.
selectsinglematnr
*MTART
*MBRSH
*MATKL
intowa_maramatnr
frommara
wherematnr=wa_maramatnr.
IFsysubrc=0.
selectsinglemaktxfrommaktintowa_maramaktxwherematnr=
wa_maramatnr.
appendwa_maratoit_mara.
http://scn.sap.com/thread/3444512
5/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
ENDIF.
topinclude:
data:it_maratypetableofty_mara,
wa_maratypety_mara.
*&SPWIZARD:DECLARATIONOFTABLECONTROL'TCL1'ITSELF
CONTROLS:TCL1TYPETABLEVIEWUSINGSCREEN0100.
*&SPWIZARD:LINESOFTABLECONTROL'TCL1'
DATA:G_TCL1_LINESLIKESYLOOPC.
DATA:OK_CODELIKESYUCOMM.
checkthis..!
Like(0)
Re:Howtoaddarecordinadatabasetablefromatablein
modulepool
ThanksBaddieigotit,butonemorethingwheneveripressenterthe
restofthefieldgoestononeditableherethe2ndlinealsogoesnon
editablesowhatcodeiwriteforthatforgettingthe2ndmaterialentry
also.Meansidontwantthedisplaymodeafterpressingenter.
Regard
Amol.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatablein
modulepool
youneedtohandlethroughprogram.
commentbelowlineinyourprogram.
MODULETCL1_CHANGE_TC_ATTR.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
notgetitherewhatshouldiwrite
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
CommentModuleTCL1_CHANGE_TC_ATTRinyou
program
http://scn.sap.com/thread/3444512
6/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
hereiamgettingthevaluescorrectandeditablealsobut
wheniampressingtheenterthevaluesgetduplicatesi
wanttoavoidit
thisisthefirstentrybutifigoforsecond
entrythenitwillcomewithfirstentryalsoandificontinue
withenterbuttonthenitwillcomeduplicateslikethis
iamattachingmyprogramalso
*&*
*&ModulePoolYTEST
*&
*&*
http://scn.sap.com/thread/3444512
7/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
*&
*&
*&*
PROGRAMYTEST.
TABLES:MAKT,MARA,MSEG.
TYPES:BEGINOFTY_MARA,
MATNRTYPEMATNR,
MAKTXTYPEMAKTX,
LGORTTYPELGORT_D,
SELTYPEX,
ENDOFTY_MARA.
data:it_MARAtypetableofty_MARA,
wa_MARAtypety_MARA.
*&SPWIZARD:DECLARATIONOFTABLECONTROL'TCL1'
ITSELF
CONTROLS:TCL1TYPETABLEVIEWUSINGSCREEN
1000.
*&SPWIZARD:LINESOFTABLECONTROL'TCL1'
DATA:G_TCL1_LINESLIKESYLOOPC.
DATA:OK_CODELIKESYUCOMM.
*&SPWIZARD:DECLARATIONOFTABLECONTROL'TC1'
ITSELF
CONTROLS:TC1TYPETABLEVIEWUSINGSCREEN
1000.
*&SPWIZARD:LINESOFTABLECONTROL'TC1'
DATA:G_TC1_LINESLIKESYLOOPC.
*&SPWIZARD:OUTPUTMODULEFORTC'TC1'.DONOT
CHANGETHISLINE!
*&SPWIZARD:UPDATELINESFOREQUIVALENT
SCROLLBAR
MODULETC1_CHANGE_TC_ATTROUTPUT.
DESCRIBETABLEIT_MARA."LINESTC1lines.
ENDMODULE.
*&SPWIZARD:OUTPUTMODULEFORTC'TC1'.DONOT
CHANGETHISLINE!
*&SPWIZARD:GETLINESOFTABLECONTROL
MODULETC1_GET_LINESOUTPUT.
G_TC1_LINES=1.
ENDMODULE.
*&SPWIZARD:INPUTMODULEFORTC'TC1'.DONOT
CHANGETHISLINE!
*&SPWIZARD:PROCESSUSERCOMMAND
MODULETC1_USER_COMMANDINPUT.
OK_CODE=SYUCOMM.
PERFORMUSER_OK_TCUSING'TC1'
'IT_MARA'
'SEL'
CHANGINGOK_CODE.
SYUCOMM=OK_CODE.
ENDMODULE.
**
*INCLUDE
TABLECONTROL_FORMS*
**
*&*
*&FormUSER_OK_TC*
*&*
FORMUSER_OK_TCUSINGP_TC_NAMETYPE
DYNFNAM
P_TABLE_NAME
P_MARK_NAME
CHANGINGP_OKLIKESYUCOMM.
http://scn.sap.com/thread/3444512
8/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
*&SPWIZARD:BEGINOFLOCALDATA
*
DATA:L_OKTYPESYUCOMM,
L_OFFSETTYPEI.
*&SPWIZARD:ENDOFLOCALDATA
*
*&SPWIZARD:Tablecontrolspecific
operations*
*&SPWIZARD:evaluateTCnameand
operations*
SEARCHP_OKFORP_TC_NAME.
IFSYSUBRC<>0.
EXIT.
ENDIF.
L_OFFSET=STRLEN(P_TC_NAME)+1.
L_OK=P_OK+L_OFFSET.
*&SPWIZARD:executegeneralandTCspecific
operations*
CASEL_OK.
WHEN'INSR'."insertrow
PERFORMFCODE_INSERT_ROWUSING
P_TC_NAME
P_TABLE_NAME.
CLEARP_OK.
WHEN'DELE'."deleterow
PERFORMFCODE_DELETE_ROWUSING
P_TC_NAME
P_TABLE_NAME
P_MARK_NAME.
CLEARP_OK.
WHEN'P'OR"topoflist
'P'OR"previouspage
'P+'OR"nextpage
'P++'."bottomoflist
PERFORMCOMPUTE_SCROLLING_IN_TCUSING
P_TC_NAME
L_OK.
CLEARP_OK.
*WHEN'L'."totalleft
*PERFORMFCODE_TOTAL_LEFTUSING
P_TC_NAME.
*
*WHEN'L'."columnleft
*PERFORMFCODE_COLUMN_LEFTUSING
P_TC_NAME.
*
*WHEN'R+'."columnright
*PERFORMFCODE_COLUMN_RIGHTUSING
P_TC_NAME.
*
*WHEN'R++'."totalright
*PERFORMFCODE_TOTAL_RIGHTUSING
P_TC_NAME.
*
WHEN'MARK'."markallfilledlines
PERFORMFCODE_TC_MARK_LINESUSING
P_TC_NAME
P_TABLE_NAME
P_MARK_NAME.
CLEARP_OK.
WHEN'DMRK'."demarkallfilledlines
PERFORMFCODE_TC_DEMARK_LINESUSING
P_TC_NAME
P_TABLE_NAME
P_MARK_NAME.
CLEARP_OK.
*WHEN'SASCEND'OR
*'SDESCEND'."sortcolumn
*PERFORMFCODE_SORT_TCUSINGP_TC_NAME
http://scn.sap.com/thread/3444512
9/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
*l_ok.
ENDCASE.
ENDFORM."USER_OK_TC
*&*
*&FormFCODE_INSERT_ROW*
*&*
FORMfcode_insert_row
USINGP_TC_NAMETYPEDYNFNAM
P_TABLE_NAME.
*&SPWIZARD:BEGINOFLOCALDATA
*
DATAL_LINES_NAMELIKEFELDNAME.
DATAL_SELLINELIKESYSTEPL.
DATAL_LASTLINETYPEI.
DATAL_LINETYPEI.
DATAL_TABLE_NAMELIKEFELDNAME.
FIELDSYMBOLS<TC>TYPE
CXTAB_CONTROL.
FIELDSYMBOLS<TABLE>TYPESTANDARD
TABLE.
FIELDSYMBOLS<LINES>TYPEI.
*&SPWIZARD:ENDOFLOCALDATA
*
ASSIGN(P_TC_NAME)TO<TC>.
*&SPWIZARD:getthetable,whichbelongstothe
tc*
CONCATENATEP_TABLE_NAME'[]'INTO
L_TABLE_NAME."tablebody
ASSIGN(L_TABLE_NAME)TO<TABLE>."not
headerline
*&SPWIZARD:getlooplinesofTableControl
*
CONCATENATE'G_'P_TC_NAME'_LINES'INTO
L_LINES_NAME.
ASSIGN(L_LINES_NAME)TO<LINES>.
*&SPWIZARD:getcurrentline*
GETCURSORLINEL_SELLINE.
IFSYSUBRC<>0."appendlinetotable
L_SELLINE=<TC>LINES+1.
*&SPWIZARD:settopline*
IFL_SELLINE><LINES>.
<TC>TOP_LINE=L_SELLINE<LINES>+1.
ELSE.
<TC>TOP_LINE=1.
ENDIF.
ELSE."insertlineintotable
L_SELLINE=<TC>TOP_LINE+L_SELLINE1.
L_LASTLINE=<TC>TOP_LINE+<LINES>1.
ENDIF.
*&SPWIZARD:setnewcursorline*
L_LINE=L_SELLINE<TC>TOP_LINE+1.
*&SPWIZARD:insertinitialline*
INSERTINITIALLINEINTO<TABLE>INDEXL_SELLINE.
<TC>LINES=<TC>LINES+1.
*&SPWIZARD:setcursor*
SETCURSORLINEL_LINE.
ENDFORM."FCODE_INSERT_ROW
*&*
*&FormFCODE_DELETE_ROW*
*&*
FORMfcode_delete_row
USINGP_TC_NAMETYPEDYNFNAM
P_TABLE_NAME
P_MARK_NAME.
*&SPWIZARD:BEGINOFLOCALDATA
http://scn.sap.com/thread/3444512
10/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
*
DATAL_TABLE_NAMELIKEFELDNAME.
FIELDSYMBOLS<TC>TYPEcxtab_control.
FIELDSYMBOLS<TABLE>TYPESTANDARDTABLE.
FIELDSYMBOLS<WA>.
FIELDSYMBOLS<MARK_FIELD>.
*&SPWIZARD:ENDOFLOCALDATA
*
ASSIGN(P_TC_NAME)TO<TC>.
*&SPWIZARD:getthetable,whichbelongstothe
tc*
CONCATENATEP_TABLE_NAME'[]'INTO
L_TABLE_NAME."tablebody
ASSIGN(L_TABLE_NAME)TO<TABLE>."not
headerline
*&SPWIZARD:deletemarkedlines*
DESCRIBETABLE<TABLE>LINES<TC>LINES.
LOOPAT<TABLE>ASSIGNING<WA>.
*&SPWIZARD:accesstothecomponent'FLAG'ofthetable
header*
ASSIGNCOMPONENTP_MARK_NAMEOF
STRUCTURE<WA>TO<MARK_FIELD>.
IF<MARK_FIELD>='X'.
DELETE<TABLE>INDEXSYSTTABIX.
IFSYSUBRC=0.
<TC>LINES=<TC>LINES1.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM."FCODE_DELETE_ROW
*&*
*&FormCOMPUTE_SCROLLING_IN_TC
*&*
*text
**
*>P_TC_NAMEnameoftablecontrol
*>P_OKokcode
**
FORMCOMPUTE_SCROLLING_IN_TCUSING
P_TC_NAME
P_OK.
*&SPWIZARD:BEGINOFLOCALDATA
*
DATAL_TC_NEW_TOP_LINETYPEI.
DATAL_TC_NAMELIKEFELDNAME.
DATAL_TC_LINES_NAMELIKEFELDNAME.
DATAL_TC_FIELD_NAMELIKEFELDNAME.
FIELDSYMBOLS<TC>TYPEcxtab_control.
FIELDSYMBOLS<LINES>TYPEI.
*&SPWIZARD:ENDOFLOCALDATA
*
ASSIGN(P_TC_NAME)TO<TC>.
*&SPWIZARD:getlooplinesofTableControl
*
CONCATENATE'G_'P_TC_NAME'_LINES'INTO
L_TC_LINES_NAME.
ASSIGN(L_TC_LINES_NAME)TO<LINES>.
*&SPWIZARD:isnolinefilled?*
IF<TC>LINES=0.
*&SPWIZARD:yes,...*
L_TC_NEW_TOP_LINE=1.
ELSE.
*&SPWIZARD:no,...*
CALLFUNCTION'SCROLLING_IN_TABLE'
EXPORTING
http://scn.sap.com/thread/3444512
11/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
ENTRY_ACT=<TC>TOP_LINE
ENTRY_FROM=1
ENTRY_TO=<TC>LINES
LAST_PAGE_FULL='X'
LOOPS=<LINES>
OK_CODE=P_OK
OVERLAPPING='X'
IMPORTING
ENTRY_NEW=L_TC_NEW_TOP_LINE
EXCEPTIONS
*NO_ENTRY_OR_PAGE_ACT=01
*NO_ENTRY_TO=02
*NO_OK_CODE_OR_PAGE_GO=03
OTHERS=0.
ENDIF.
*&SPWIZARD:getactualtcandcolumn*
GETCURSORFIELDL_TC_FIELD_NAME
AREAL_TC_NAME.
IFSYSTSUBRC=0.
IFL_TC_NAME=P_TC_NAME.
*&SPWIZARD:etactualcolumn*
SETCURSORFIELDL_TC_FIELD_NAMELINE1.
ENDIF.
ENDIF.
*&SPWIZARD:setthenewtopline*
<TC>TOP_LINE=L_TC_NEW_TOP_LINE.
ENDFORM."
COMPUTE_SCROLLING_IN_TC
*&*
*&FormFCODE_TC_MARK_LINES
*&*
*marksallTableControllines
**
*>P_TC_NAMEnameoftablecontrol
**
FORMFCODE_TC_MARK_LINESUSINGP_TC_NAME
P_TABLE_NAME
P_MARK_NAME.
*&SPWIZARD:EGINOFLOCALDATA
*
DATAL_TABLE_NAMELIKEFELDNAME.
FIELDSYMBOLS<TC>TYPEcxtab_control.
FIELDSYMBOLS<TABLE>TYPESTANDARDTABLE.
FIELDSYMBOLS<WA>.
FIELDSYMBOLS<MARK_FIELD>.
*&SPWIZARD:ENDOFLOCALDATA
*
ASSIGN(P_TC_NAME)TO<TC>.
*&SPWIZARD:getthetable,whichbelongstothe
tc*
CONCATENATEP_TABLE_NAME'[]'INTO
L_TABLE_NAME."tablebody
ASSIGN(L_TABLE_NAME)TO<TABLE>."not
headerline
*&SPWIZARD:markallfilledlines*
LOOPAT<TABLE>ASSIGNING<WA>.
*&SPWIZARD:accesstothecomponent'FLAG'ofthetable
header*
ASSIGNCOMPONENTP_MARK_NAMEOF
STRUCTURE<WA>TO<MARK_FIELD>.
<MARK_FIELD>='X'.
ENDLOOP.
ENDFORM."fcode_tc_mark_lines
*&*
*&FormFCODE_TC_DEMARK_LINES
http://scn.sap.com/thread/3444512
12/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
*&*
*demarksallTableControllines
**
*>P_TC_NAMEnameoftablecontrol
**
FORMFCODE_TC_DEMARK_LINESUSINGP_TC_NAME
P_TABLE_NAME
P_MARK_NAME.
*&SPWIZARD:BEGINOFLOCALDATA
*
DATAL_TABLE_NAMELIKEFELDNAME.
FIELDSYMBOLS<TC>TYPEcxtab_control.
FIELDSYMBOLS<TABLE>TYPESTANDARDTABLE.
FIELDSYMBOLS<WA>.
FIELDSYMBOLS<MARK_FIELD>.
*&SPWIZARD:ENDOFLOCALDATA
*
ASSIGN(P_TC_NAME)TO<TC>.
*&SPWIZARD:getthetable,whichbelongstothe
tc*
CONCATENATEP_TABLE_NAME'[]'INTO
L_TABLE_NAME."tablebody
ASSIGN(L_TABLE_NAME)TO<TABLE>."not
headerline
*&SPWIZARD:demarkallfilledlines*
LOOPAT<TABLE>ASSIGNING<WA>.
*&SPWIZARD:accesstothecomponent'FLAG'ofthetable
header*
ASSIGNCOMPONENTP_MARK_NAMEOF
STRUCTURE<WA>TO<MARK_FIELD>.
<MARK_FIELD>=SPACE.
ENDLOOP.
ENDFORM."fcode_tc_mark_lines
*&*
*&ModuleUSER_COMMAND_1000INPUT
*&*
*text
**
MODULEUSER_COMMAND_1000INPUT.
ENDMODULE."USER_COMMAND_1000INPUT
*&*
*&ModuleGET_MATINPUT
*&*
*text
**
MODULEGET_MATINPUT.
CALLFUNCTION'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input=wa_maramatnr
IMPORTING
OUTPUT=wa_maramatnr
.
selectsinglematnr
*MTART
*MBRSH
*MATKL
intowa_maramatnr
frommara
wherematnr=wa_maramatnr.
IFsysubrc=0.
selectsinglemaktxfrommaktintowa_maramaktx
wherematnr=wa_maramatnr.
appendwa_maratoit_mara.
ENDIF.
ENDMODULE."GET_MATINPUT
http://scn.sap.com/thread/3444512
13/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
heyyouneedtovalidatetherecord..!
ThinkbeforepostingthequestionandalsosomeRNDor
runyouprogramindebugmode.
Mostlysapscnmoderatordidntseeyourquestion,they
wouldhaveblockquestioniftheywouldhaveseenthis
question.
Trytodoyourself...ifyoudidntgetcomebacktome.
Thereisnothinginthat...readsyucommandvalidatethe
input...!
Like(0)
Thisreplyhasbeenhidden.Thiscanhappenifthemessagehasbeen
hiddenbyamoderator,orhasbeenreportedasabusive.
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
Amol
AsafirststepoflearningSAPhasgivenusDWDMtcode
whereithasvariousexamplesofhowtoimplementthe
variouscontrols.KeepreadingonSCN..readallblogsdocs
andpostyourdoubt.Wewillbehappytohelp/learnwith
you
Nabheet
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
DearManish,
FromyourinternaltableTABLEIT_ZEMP1,canyouidentifywhichrecordsarenewlyadded?Ifnot
makesomeflagintheinternaltablethatspecifywhetheritisanewlycreatedrecordormodifiedone.
Then,uponsaveaction,
loopatinternaltable.
ifflagismodify,usemodifystatement
else
insertstatement.
endif
endloop
OR,
totallydeletetherecordsforthatprimarykeyandReinserteverything.
"Examplefromoneofmine...
ifinsert_or_update='I'.
insertintozsdt_inqforcastVALUESwa_zsdt_forcast.
else.
UPDATEzsdt_inqforcastFROMwa_zsdt_forcast.
http://scn.sap.com/thread/3444512
14/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
endif.
Where,zsdt_inqforcastismyztablewa_zsdt_forcastisasamestructureofzsdt_inqforcast.
Regards,
Venkat
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiVenkat,
Iusedinsertintozemp1VALUESwa_zemp1asperyourapproach.Butwhenaminserting1
ormorenewentriesinthetablecontrol,thedatabasetableinsertsonly1newrecordand
thattoowiththeMANDTfieldhavingarecordonly.Theremaining3fieldsareblank.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Makesure
Youneedtosetthatinaloop.
secondly,allfiledsinthewa_zemp1areassignedproperly.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiVenkat,
Ididuseitinaloopandthefieldsinwa_zemp1areassignedproperly.IthinkImay
havetoeradicatetheMANDTfieldfrommytablecontrol.perhapsthatmightbecausing
problems.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Noitisnotbecauseofmandt..
Canyoutellmethestructureofyourztable.
Iwanttoseewhatisyourprimarykey?
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiVenkat,
Myztable(zemp1)hasMANDT,ID,NAME,COMPANY.MANDTandIDaremy
primarykeys.
Like(0)
http://scn.sap.com/thread/3444512
15/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
iamcreatingatableformanualentryinmodulepoolbutproblemiswhenever
userentermaterialnothedescriptionshouldautomaticallycomesinother
fieldandatlastthedatashouldsaveinthetableiwillattachyouthescreen
shotplsguideme.whenuserpressenterthefieldentrydisappears.
Like(0)
HelpfulAnswer Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiManishMalakar,
Seethisexampleandtrylikethis
Flowlogicinscreen9001
processbeforeoutput.
loopatit_finalintowa_finalwithcontrolvcontrolcursor
vcontrolcurrent_line.
endloop.
modulestatus_9001.
*
processafterinput.
*chain.
fieldrollno.
*endchain.
http://scn.sap.com/thread/3444512
16/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
loopatit_final.
chain.
fieldwa_finalname.
fieldwa_finalage.
fieldwa_finalgropu.
fieldwa_finalmarks1.
fieldwa_finalmarks2.
fieldwa_finalmarks3.
fieldwa_finaltot.
modulewa_final.
endchain.
endloop.
moduleuser_command_9001.
Code
TABLES:zram1,.
DATA:wa_finalTYPEzram1.
DATA:it_finalTYPETABLEOFzram1.
DATA:rollnoTYPEzram1rollno.
CONTROLS:vcontrolTYPETABLEVIEWUSINGSCREEN9001.
CALLSCREEN9001.
*&*
*&ModuleSTATUS_9001OUTPUT
*&*
*text
**
MODULEstatus_9001OUTPUT.
SETPFSTATUS'9001'.
SETTITLEBAR'9001'.
ENDMODULE."STATUS_9001OUTPUT
*&*
*&ModuleUSER_COMMAND_9001INPUT
*&*
*text
**
MODULEuser_command_9001INPUT.
CASEsyucomm.
WHEN'CREATE'.
MODIFYzram1FROMTABLEit_final.
CLEARit_final.
CLEARrollno.
IFsysubrc=0.
MESSAGE:'CREATED....' TYPE'S'.
ENDIF.
WHEN'DISPLAY'.
SELECT*FROMzram1INTOTABLEit_finalWHERErollno=rollno.
WHEN'UPDATE'.
MODIFYzram1FROMTABLEit_final.
CLEARit_final.
CLEARrollno.
http://scn.sap.com/thread/3444512
17/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
IFsysubrc=0.
MESSAGE:'UPDATED....' TYPE'S'.
ENDIF.
WHEN'DELETE'.
DELETEzram1FROMTABLEit_final.
CLEARit_final.
CLEARrollno.
IFsysubrc=0.
MESSAGE:'DELETED....' TYPE'S'.
ENDIF.
WHEN'EXIT'.
LEAVEPROGRAM.
WHENOTHERS.
ENDCASE.
ENDMODULE."USER_COMMAND_9001INPUT
*&*
*&Modulewa_finalINPUT
*&*
*text
**
MODULEwa_finalINPUT.
wa_finalrollno=rollno.
APPENDwa_finalTOit_final.
ENDMODULE."wa_finalINPUT
Like(2)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiRamesh,
myMODIFYstatementisnotinsertingnewrecordsinmydatabasetable.Ifuwant,Icancopy
pastemycodeforyourreference(onlythePAIpartasthatiswheretheissueis).
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hi,
NothingwrongusingtheModifystatementanditshouldworkasperyourrequirement.However
pleasecheckthebelownotes.Iguessitsolvesyourproblem.
Switchesoffautomaticclienthandling.Thisallowsyoutoeditdataacrossallclientsevenwhen
dealingwithclientspecifictables.Theclientfieldistreatedlikeanormaltablefieldthatcanbe
programmedtoacceptvaluesinthetableworkareadbtabor*dbtabwherethelinetobe
editedoccurs.
Information:
Thevaluesforthelinetobeinsertedorupdatedarenottakenfromthetableworkareadbtab,but
fromtheexplicitlyspecifiedworkareawa.Whendoingthis,thedataisreadfromlefttoright
accordingtothestructureofthetableworkareadbtab
http://help.sap.com/saphelp_45b/helpdata/en/34/8e72c46df74873e10000009b38f9b8/content.htm.
Sincethestructureofwaisnottakenintoaccount,theworkareawamustbeatleastaswideas
thetableworkareadbtabandthealignmentoftheworkareawamustcorrespondtothe
http://scn.sap.com/thread/3444512
18/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
alignmentofthetableworkarea.Otherwise,aruntimeerroroccurs.
Thanks,
Kiran.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
iamcreatingatableformanualentryinmodulepoolbutproblemiswheneveruserenter
materialnothedescriptionshouldautomaticallycomesinotherfieldandatlastthedata
shouldsaveinthetableiwillattachyouthescreenshotplsguideme.whenuserpress
enterthefieldentrydisappears.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiRamesh,
ThisisthescreenshotofthePAIpartofmycode.
ThisisafterIusedVladimirErakovic'sapproach.InitiallyIusedthesameapproachasyourcode.
ThescreenshotofmyTOPincludeisgivenbelowthePAIscreenshot.
http://scn.sap.com/thread/3444512
19/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Messagewaseditedby:ManishMalakar
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiRamesh,
Thisishowmyflowlogiclookslike:
InthemoduleCHECKLISTthisisthecodeI'vewritten:
MyPAIcontainsthefollowinglogic:
http://scn.sap.com/thread/3444512
20/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Now,afterIgettherecords,Iwishtoaddanewrecordinmydatabasetable.
SoIenterthenewrecordasshownbelow:
Afterthis,therecordgetsaddedinthedatabasetable,buttheprimarykeydisappears
http://scn.sap.com/thread/3444512
21/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Hence,whenIcheckmydatabasetable,Thenewrecordistherebutwithouttheprimarykey
(whichistheID).
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
iamcreatingatableformanualentryinmodulepoolbutproblemiswheneveruserenter
materialnothedescriptionshouldautomaticallycomesinotherfieldandatlastthedatashould
saveinthetableiwillattachyouthescreenshotplsguideme.whenuserpressenterthefield
entrydisappears.
Like(0)
http://scn.sap.com/thread/3444512
22/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
VladimirErakovic Oct26,20137:43PM (inresponsetoManishMalakar)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiManish,
Youcandolikethis:
TYPES:BEGINOFt_uplate,
flagTYPEc,
bukrsLIKEz_uplatbukrs,
brkonLIKEz_uplatbrkon,
bruplLIKEz_uplatbrupl,
brnalbnkLIKEz_uplatbrnalbnk,
wrbtrLIKEz_uplatwrbtr,
waersLIKEz_uplatwaers,
datuplLIKEz_uplatdatupl,
banklLIKEz_uplatbankl,
bankaLIKEbnkabanka,
napomLIKEz_uplatnapom,
datumLIKEz_uplatdatum,
vremeLIKEz_uplatvreme,
ukorLIKEz_uplatukor,
ENDOFt_uplate.
DATA:g_uplate_itabTYPEt_uplateOCCURS0,
recTYPEt_uplate.
DATA:upltTYPEz_uplat.
LOOPATg_uplate_itabINTOrec.
MOVECORRESPONDINGrecTOuplt.
MODIFYz_uplatFROMuplt.
ENDLOOP.
Bestregards,
Vladimir
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Dear VladimirErakovic
ExecutetheInsertqueryonADDbutton,andShareyourCodethenItellyou.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiAlok,
Idon'tunderstand,tellmewhat?
ThatcodeispartofmySavesubroutinefromaprogramthatworksfineinproductionfor
coupleofmonths.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
InwhichTableyouwanttoInsertandfromwhichInternalTable.
http://scn.sap.com/thread/3444512
23/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Inz_uplatfromg_uplate_itab(whichisinternaltablethatIuseintablecontrol).
And?
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
ok
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
YouarenotabletomodifythefieldsinitorSomethingElse.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
WhydoyouthinkIcan't?
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodule
pool
YouareNotabletoModify.IfitCorrectthenyouarenotabletoModify
maybeuarenotgivingtransportingparameterorIndex(i.erownumber
)oryoucanuseUpdatequeryforthem
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiVladimir,
I'lltryoutyourcode,butisntMOVECORRESPONDINGbadperformancewise?
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hi
ManishMalakar,
http://scn.sap.com/thread/3444512
24/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Itsprobablywithyourdatabasesettingattribute.
Makesurethatyouhavesetallthefieldsaskeyfieldsasrequiredifyouwanttoinsertanew
recordforeverynewentryintablecontrol.Elseanewrecordwillonlybeinsertedonceper
keyfield.
oryoucouldgivetheadditionACCEPTINGDUPLICATEKEYStotheinsertstatement.
INSERT<target>FROMTABLE<itab>[ACCEPTINGDUPLICATEKEYS].
Like(1)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiSushmitha,
Couldyoupleaseexplainwhatyoumeantbystatingthatallfieldsneedtobesetaskey
fields?Ihave4fieldsinmydatabasetable(MANDT,ID,NAME,COMPANY)outof
whichMANDTandIDaremyprimarykeys.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hey,ifyourdatabasetableandyourinternaltablehavethesamefields(mandt
doesn'tcount)thenyoudon'thavetomovecorespondingbutmodifyfromwork
areainaloop,
althoughitwillworkbothways.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
iamcreatingatableformanualentryinmodulepoolbutproblemiswhenever
userentermaterialnothedescriptionshouldautomaticallycomesinother
fieldandatlastthedatashouldsaveinthetableiwillattachyouthescreen
shotplsguideme.whenuserpressenterthefieldentrydisappears.
Like(0)
http://scn.sap.com/thread/3444512
25/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Ididn'tknowwhatyourfieldswerewhenIpostedthat.Ithoughtyoumustbe
creatingatableentrywithoneortwofieldsrepeating,eg,inthiscase,ifyouare
creatinganewentrywiththesameIDbutdifferentnameandcompany,itwillnot
create,sincetherealreadyexistsanentryforthatID.Toenablethatyouneedtoset
allfieldsasprimary.Butnowonseeingyourfieldnames,Iassume,sucha
situationwillnotcomeup.HereIguessitsfineifonlymandtandIDaresetas
primarykeys.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
iamcreatingatableformanualentryinmodulepoolbutproblemiswhenever
userentermaterialnothedescriptionshouldautomaticallycomesinother
fieldandatlastthedatashouldsaveinthetableiwillattachyouthescreen
shotplsguideme.whenuserpressenterthefieldentrydisappears.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiVladimir,
ThisisthescreenshotofthePAIpartofmycode.
ThisisafterIusedVladimirErakovic'sapproach.InitiallyIusedthesameapproachasyourcode.
ThescreenshotofmyTOPincludeisgivenbelowthePAIscreenshot.
http://scn.sap.com/thread/3444512
26/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Doesitworks?
Ifyes,youmayshareawardsandclosethisdiscussion.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiVladimir,
sorry,theapproachisntworking.
Like(0)
http://scn.sap.com/thread/3444512
27/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
VladimirErakovic Oct27,20136:22PM (inresponsetoManishMalakar)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Itshouldwork.
YourdatabasetablethatyoumodifyisZEMP1?
InternaltableintablecontrolisIT_ZEMP1andworkareaisWA_ZEMP1?
Ican'tpostthewholeprogramherebutIwillmakestepbystepguidetodialog
programmingthesedays.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Yes,thedatabasetablewhichIwanttomodifyisZEMP1.IT_ZEMP1and
WA_ZEMP1aretheinternaltableandworkareaofthestructureTY_ZEMP1
respectively.WAistheworkareawhichisoftypedatabasetableZEMP1.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
HiManish,
Canyoualsosharethecodeinyourscreenpainter?
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hi SusmithaSusanThomas
Belowarethescreenshotsprovided.Thefirstoneismydatabasetable,thesecondone
ismyPAIasperyourapproach.Howeverthenewrecordisntgettingaddedinmy
databasetable.InmyscreenpainterIhavenotusedMANDTfieldasIdontwantittobe
displayed.
http://scn.sap.com/thread/3444512
28/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
StartdebuggerandseeifIT_ZEMP1hasanyvalues.Seconldyputacommitwork
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Afterdebugging,IfoundoutthatIT_ZEMP1hasallthevaluesasperthe
selectoptions.IdidputCOMMITWORKafterMODIFYbutitsstillnotworking.
Screenshot(1)showsalltherecorddisplayedasperselectoptions.Thenam
addinganewrecord(IDnumber23)asshowninthesamescreenshot.
Screenshot(2)showsthatasIpressthe'SAVE'button,themessageis
displayedthatthenewrecordissavedbutalsothenewrecorddisappears
fromthetable.
Screenshot(3)showsthataftersavingthenewrecordwhenIgotothe
databasetableZEMP1,Ifindthatthenewrecordhasntbeeninserted.
(1)
http://scn.sap.com/thread/3444512
29/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
(2)
(3)
http://scn.sap.com/thread/3444512
30/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Messagewaseditedby:ManishMalakar
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodule
pool
Thereasonisonceyouenteryour23record.Doa/Hstartdebugging.
InsidethelooptherecordisnotgettingappendedtoIT_EMP1table.Puta
breakpointjustbeforewhereyouaremodifyingthedatabasetableyou
willtheinternaltablehasonlytheoriginalrecords.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatablein
modulepool
That'sright.Onlytheoriginalrecordsareshowinginthedatabase
table.Sowhyisthenewrecordnotgettingappendedinspiteofusing
theMODIFYstatement?WhereamIgoingwrong?
ThisisthescreenshotofthedebuggerafterIexecute/H.Ihave
enteredonly10recordsinselectoptionsandpressed'SUBMIT'.
http://scn.sap.com/thread/3444512
31/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Like(0)
HelpfulAnswer Re:Howtoaddarecordinadatabasetable
fromatableinmodulepool
Becauseyourloopisempty.Itshouldlooklikethis:
LOOPATg_uplate_itab.
CHAIN.
FIELDg_uplate_wabrupl.
FIELDg_uplate_wabrnalbnk.
FIELDg_uplate_wawrbtr.
FIELDg_uplate_wawaers.
FIELDg_uplate_wadatupl.
FIELDg_uplate_wabankl.
FIELDg_uplate_wabanka.
FIELDg_uplate_wanapom.
MODULEtc_uplate_modifyONCHAINREQUEST.
ENDCHAIN.
ENDLOOP.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
HeyVladimir,
asperyourapproachImadethefollowingchanges.
Thisishowmyflowlogiclookslike:
http://scn.sap.com/thread/3444512
32/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
InthemoduleCHECKLISTthisisthecodeI'vewritten:
MyPAIcontainsthefollowinglogic:
Now,afterIgettherecords,Iwishtoaddanewrecordin
mydatabasetable.
SoIenterthenewrecordasshownbelow:
http://scn.sap.com/thread/3444512
33/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Afterthis,therecordgetsaddedinthedatabasetable,but
theprimarykeydisappears
Hence,whenIcheckmydatabasetable,Thenewrecordis
therebutwithouttheprimarykey(whichistheID).
Whyisthishappening?
Like(0)
http://scn.sap.com/thread/3444512
34/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
VladimirErakovic Oct31,20133:49PM (inresponsetoManishMalakar
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
HiManish,
Trythisinyouchecklistmodule:
MODULEchecklistINPUT.
MODIFYit_zemp1
FROMwa_zemp1
INDEXit_zemp1current_line.
ENDMODULE.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
Ididthat,butamgettingthefollowingerror:
Ihavetakenit_zemp1typestandardtableofzemp1(my
databasetable)andwa_zemp1typezemp1.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
HiManish,
TrytoaddWITHHEADERLINEinit_zemp1declaration.
Likethis:
DATA:it_zemp1TYPESTANDARDTABLEOFty_zemp1
WITHHEADERLINE.
Headerlineislikeaworkarea..
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
SoeventhoughIhaveusedaworkarea,Ihavetodeclare
theit_zemp1'WITHHEADERLINE'?
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
http://scn.sap.com/thread/3444512
35/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
ButjustbecauseofCURRENTLINE.Itwouldbeeverything
mucheasierforyouifyouusedtablecontrolwizard..
Like(0)
Re:Howtoaddarecordinadatabasetablefromatablein
modulepool
becauseinLoopat_itzemp1andendloopyouneedtocheckif
entryisnottheirinIT_ZEMP1thenappendittointernaltable.
Plusmoveyourusercommandafterendloop.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatablein
modulepool
HiManish,
WhenIaskedforthecodeinthescreenpainter,thiswasthe
screenshotIwasaskingfor.
Youneedtodoalotofadditionshere.Youneedtoloopthrough
allthefields,modifythetableintablecontrolforeveryrecord
inputted.Thenonlynewfieldswillbeadded.
Checkanysamplecodelikethecodegivenby RameshT
Re:Howtoaddarecordinadatabasetablefromatablein
modulepool
andmakeappropriatechanges.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatable
inmodulepool
Hi SusmithaSusanThomas,
ItriedtheapproachasperRamesh,butIdohavea
problem:
Thisishowmyflowlogiclookslike:
InthemoduleCHECKLISTthisisthecodeI'vewritten:
http://scn.sap.com/thread/3444512
36/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
MyPAIcontainsthefollowinglogic:
Now,afterIgettherecords,Iwishtoaddanewrecordin
mydatabasetable.
SoIenterthenewrecordasshownbelow:
Afterthis,therecordgetsaddedinthedatabasetable,but
theprimarykeydisappears
http://scn.sap.com/thread/3444512
37/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Hence,whenIcheckmydatabasetable,Thenewrecordis
therebutwithouttheprimarykey(whichistheID).
Whyisthishappening?
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hi,
WHEN'SAVE'.
LOOPATIT_ZME1INTOWA_ZEMP1."checkurinternaltable
MOVECORRESPONDINGWA_ZEMP1TOWA."YouCancheckWafiledassignvalueiscorrector
not
MODIFYZEMP1FROMWA.
CLEAR:WA,WA_ZEMP1."uchecksysubrcEQ0ornot
ENDLOOP.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hi LingarajPattajoshi
Itriedthatapproachbefore,butitdidntyieldtheresult.
IusedMODIFYwiththeinternaltable(IT_ZEMP1whichisoftypeZEMP1itself)andused
http://scn.sap.com/thread/3444512
38/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
COMMITWORK.Stillitdidntwork.
Afterdebugging,IfoundoutthatIT_ZEMP1hasallthevaluesaspertheselectoptions.
Screenshot(1)showsalltherecorddisplayedasperselectoptions.Thenamaddinganew
record(IDnumber23)asshowninthesamescreenshot.
Screenshot(2)showsthatasIpressthe'SAVE'button,themessageisdisplayedthatthenew
recordissavedbutalsothenewrecorddisappearsfromthetable.
Screenshot(3)showsthataftersavingthenewrecordwhenIgotothedatabasetableZEMP1,I
findthatthenewrecordhasntbeeninserted.
(1)
(2)
(3)
http://scn.sap.com/thread/3444512
39/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Trytousethislittlesnippet:
01. WHEN'SAVE'.
02. PERFORMupdate_dbTABLESit_zemp1.
03.
04. *&*
05. *&Formupdate_db
06. *&*FORMupdate_dbTABLESit_zemp1STRUCTUREzemp1.
07.
08. DATA:n1TYPEi,
09. n2TYPEi,
10. c1TYPEcLENGTH5,
11. c2TYPEcLENGTH5,
12. msgTYPEcLENGTH300,
13. orefTYPEREFTOcx_root.
14.
15. *Firstremoveduplicate
16. DESCRIBETABLEit_zemp1LINESn1.
17. SORTit_zemp1BYid.
18. DELETEADJACENTDUPLICATESFROMit_zemp1COMPARINGid.
19. DESCRIBETABLEit_zemp1LINESn2.
20. IFn1NEn2.
21. SUBTRACTn2FROMn1.
22. WRITEn1TOc1.
23. SHIFTc1LEFTDELETINGLEADING'0'.
24. CONCATENATEc1'duplicaterecordsweredeleted'INTOmsgSEPARATEDBYspace.
25. MESSAGEmsgTYPE'I'.
26. ENDIF.
27.
28. *Trytoupdatedatabase
29. TRY.
30. INSERTzemp1FROMTABLEit_zemp1ACCEPTINGDUPLICATEKEYS.
31. n1=sydbcnt.
32. MODIFYzemp1FROMTABLEit_zemp1.
33. n2=sydbcnt.
34. COMMITWORK.
35. WRITEn1TOc1.
36. SHIFTc1LEFTDELETINGLEADING'0'.
37. SUBTRACTn1FROMn2.
38. WRITEn2TOc2.
39. SHIFTc2LEFTDELETINGLEADING'0'.
40. CONCATENATEc1'recordsinserted'c2'recordsupdated'INTOmsgSEPARATEDBYspace.
41. MESSAGEmsgTYPE'S'.
42. CATCHcx_rootINTOoref.
http://scn.sap.com/thread/3444512
40/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
43. ROLLBACKWORK.
44. msg=oref>get_text().
45. MESSAGEmsgTYPE'E'.
46. ENDTRY.
47.
48. ENDFORM."update_db
Soyoubetterunderstandwhatishappening.
NB:Checkifyoudidcreateindex(es)withuniquekeyonyourztable,thatcouldalsogenerate
duplicaterecords.
Regards,
Raymond
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Hi RaymondGiuseppi,
Therearenoduplicaterecordsinmytable(ifulookatmyscreenshotprovidedbelow).Solines
17to27arenotrequired.Nowamonlyconcernedwithaddinganewrecordtomydatabase
tableZEMP1.SoIusedMODIFYwithCOMMITWORKasshowninline33and35.
Afterdebugging,IfoundoutthatIT_ZEMP1hasallthevaluesaspertheselectoptions.Sono
issuesthere.
Screenshot(1)showsalltherecorddisplayedasperselectoptions.Thenamaddinganew
record(IDnumber23)asshowninthesamescreenshot.
Screenshot(2)showsthatasIpressthe'SAVE'button,themessageisdisplayedthatthenew
recordissavedbutalsothenewrecorddisappearsfromthetable.
Screenshot(3)showsthataftersavingthenewrecordwhenIgotothedatabasetableZEMP1,I
findthatthenewrecordhasntbeeninserted.
(1)
(2)
http://scn.sap.com/thread/3444512
41/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
(3)
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
CheckthatyourinternaltablewasactuallyfilledinPAI.IhopeSAVEisnotanexitfunction
keyandthatthemoduleforuser_commandwascodedinPAIaftertheLOOPwith
CONTROLandthechecks.
01. processafterinput.
02. *Exitfunctioncodes
03. moduleuser_commandatexitcommand.
04. *LOOPfortablecontrol
05. LOOPATitab.
06. chain.
07. fielditabf1.
08. fielditabf2.
09. MODULEitab_check.
10. endchain.
11. fielditabf3.
http://scn.sap.com/thread/3444512
42/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
12.
13.
14.
15.
MODULEitab_modify.
ENDLOOP.
*Applicationfunctioncodes
MODULEuser_command."Herethesaveismanaged
NeverthelessyourSuccessmessageisnotsignificantasyoudon'tevenchecksysubrc
(norsydbcnt)
Regards,
Raymond
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
SorryRaymond,myapologiesforbeingcarelessregardingSYSUBRC.NowIhave
rectifiedmycodeinthePAIandcheckedSYSUBRCasperscreenshot(1).
So,Iwantedtodisplaythefirst10records,soIpressedthe'SUBMIT'buttonand
executed/Handwenttothedebuggerandfoundoutthattherecordsareenteredin
theinternaltable.Also,afterIclick'SAVE',SYSUBRCiszeroasperscreenshot(2).
ThenwhyismyMODIFYstatementnotappendingthenewrecordinthedatabase
table?
Bytheway,'SAVE'buttondoesnothaveatype'E'functionkey.Itsusedinthenormal
wayinthePFSTATUS.
(1)
(2)
http://scn.sap.com/thread/3444512
43/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
YouputtheLOOPATitabAFTERtheuser_command,soSAVEcommandexecute
oncurrentvaluesintheprogramandnotvaluesinthedynpro.
AlsoyoumissedsomecodeintheLOOP,wheredoyouupdatetheinternaltable?
YoumustaddamoduleintheLOOP/ENDLOOPthatupdatetheinternaltable.The
LOOP/ENDLOPMUSTbeinthePAIlogic,notinamodule,andmustexecutea
modulethatupdateinternaltablewithindexequalto<controlname>current_line.
Regards,
Raymond
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Manish,howdidyoumadetablecontrol?Withwizard?
Doesflowlogicinyouscreenlooklikethis?
PROCESSBEFOREOUTPUT.
MODULEstatus_0100.
*&SPWIZARD:PBOFLOWLOGICFORTABLECONTROL'TC_UPLATE'
MODULEtc_uplate_change_tc_attr.
*&SPWIZARD:MODULETC_UPLATE_CHANGE_COL_ATTR.
LOOPATg_uplate_itab
INTOg_uplate_wa
WITHCONTROLtc_uplate
CURSORtc_uplatecurrent_line.
MODULEtc_uplate_get_lines.
*&SPWIZARD:MODULETC_UPLATE_CHANGE_FIELD_ATTR
ENDLOOP.
PROCESSAFTERINPUT.
*&SPWIZARD:PAIFLOWLOGICFORTABLECONTROL'TC_UPLATE'
LOOPATg_uplate_itab.
CHAIN.
FIELDg_uplate_wabrupl.
http://scn.sap.com/thread/3444512
44/45
26/04/2016
Howtoaddarecordinadatabasetablefroma...|SCN
FIELDg_uplate_wabrnalbnk.
FIELDg_uplate_wawrbtr.
FIELDg_uplate_wawaers.
FIELDg_uplate_wadatupl.
FIELDg_uplate_wabankl.
FIELDg_uplate_wabanka.
FIELDg_uplate_wanapom.
MODULEtc_uplate_modifyONCHAINREQUEST.
ENDCHAIN.
ENDLOOP.
MODULEtc_uplate_user_command.
Like(1)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
NoVladimir,Icreatedthetablecontrolmanually.Didn'tusewizard.
Like(0)
Re:Howtoaddarecordinadatabasetablefromatableinmodulepool
Bossdolikethis
Loop
Module>Readtableit_zemp1withkeyserialnuiffoundmodifyit_zemp1elseappendto
it_zemp1.
endloop
moduleSave_ok.
Like(0)
Share
SiteIndex
Privacy
Tweet
ContactUs
TermsofUse
http://scn.sap.com/thread/3444512
SAPHelpPortal
LegalDisclosure
Copyright
FollowSCN
45/45